package com.gavindon.android.widget

import android.content.Context
import android.util.AttributeSet
import android.view.KeyEvent
import android.view.View
import androidx.recyclerview.widget.RecyclerView

/**
 * description:
 * Created by liNan on  2022-1-26 10:39
 */
class CustomRecyclerView : RecyclerView {

    constructor(context: Context) : this(context, null)
    constructor(context: Context, attrs: AttributeSet?) : this(context, attrs, 0)
    constructor(context: Context, attrs: AttributeSet?, defStyleAttr: Int) : super(
        context,
        attrs,
        defStyleAttr
    ) {
        initView()
    }

    private fun initView() {
        descendantFocusability = FOCUS_AFTER_DESCENDANTS
        setHasFixedSize(true)
        setWillNotDraw(true)
        overScrollMode = View.OVER_SCROLL_NEVER
        isChildrenDrawingOrderEnabled = true

        clipChildren = false
        clipToPadding = false

        isClickable = false
        isFocusable = true
        isFocusableInTouchMode = true
        /**
        防止RecyclerView刷新时焦点不错乱bug的步骤如下:
        (1)adapter执行setHasStableIds(true)方法
        (2)重写getItemId()方法,让每个view都有各自的id
        (3)RecyclerView的动画必须去掉
         */
        itemAnimator = null

    }


    override fun onKeyDown(keyCode: Int, event: KeyEvent?): Boolean {
        when (keyCode) {
            KeyEvent.ACTION_DOWN -> {}
            KeyEvent.ACTION_UP -> {}
        }


        return super.onKeyDown(keyCode, event)
    }
}